<template>
  <div>
    <div>
      <div style="margin-top: 15px;">
        <el-col :span="6">
          <el-input placeholder="请输入优先级名进行查询" v-model="getByName" class="input-with-select">

            <el-button slot="append" icon="el-icon-search" @click="selByName">查询</el-button>
          </el-input>
        </el-col>
        <el-button type="infor" style="position: relative;left: 850px;" @click="addPriority">新增<i class="el-icon-upload el-icon--right"></i></el-button>
      </div>
    </div>
    <el-table :data="getPrioritByPage" style="width: 100%">
      <el-table-column prop="priorityId" label="编号"></el-table-column>
      <el-table-column prop="priorityDesc" label="优先级"></el-table-column>
      <el-table-column prop="moduleState" label="状态"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-link icon="el-icon-edit" @click="changePriority(scope.row.priorityId)" type="primary">修改</el-link>
          <el-link icon="el-icon-edit" @click="delPriority(scope.row.priorityId)" type="primary">删除</el-link>
          <!-- <el-link icon="el-icon-edit" @click="changemessage(scope.row)" type="primary"> -->


          <el-link icon="el-icon-edit" type="primary" @click="closePriority(scope.row.priorityId)">
            {{scope.row.moduleState=='有效'?'禁用':'启用'}}
          </el-link>



          <!-- </el-link> -->
        </template>
      </el-table-column>

    </el-table>

    <el-pagination fixed @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pages.current"
      :page-sizes="[1, 2, 3, 4]" :page-size="pages.size" layout="total, sizes, prev, pager, next, jumper" :total="pages.total">
    </el-pagination>

    <el-dialog title="添加优先级" :visible.sync="dialogVisible" width="30%" >

      <el-form>
        <el-input type="text" placeholder="优先级名称" v-model="priorityName"></el-input>
        <!-- <textarea cols="48" rows="2" placeholder="项目描述" v-model="changeprojectinfo.projectDesc"></textarea> -->


      </el-form>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="sureadd">确 定</el-button>
      </span>
    </el-dialog>



    <el-dialog title="修改优先级" :visible.sync="dialogVisible2" width="30%" >
      <el-form>
        <el-input type="text" placeholder="优先级名称" v-model="changepriorityName"></el-input>
        <!-- <textarea cols="48" rows="2" placeholder="项目描述" v-model="changeprojectinfo.projectDesc"></textarea> -->


      </el-form>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="surechange">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "priority",
    data() {
      return {
        getPrioritByPage: [],
        pages: {},
        priorityName: "",
        dialogVisible: false,
        dialogVisible2: false,
        changepriorityName:"",
        priorityId:0,
        getByName:""
      }
    },
    methods: {
      getAllPriority(current, size) {
        this.$http.post("defectPriority/getAllPriority", {
          "current": current,
          "size": size
        }).then(resp => {
          this.getPrioritByPage = resp.data.data.records
          this.pages = resp.data.data
        })
      },
      handleSizeChange(val) {

        this.pages.size = val
        this.getAllPriority(this.pages.num, val)
      },
      handleCurrentChange(val) {
        this.pages.current = val
        this.getAllPriority(val, this.pages.size)
      },
      addPriority() {
        this.dialogVisible = true
      },
      sureadd() {
        let accountName = JSON.parse(localStorage.getItem("loginUser")).accountName
        this.$http.post("defectPriority/addPriority", {
          "accountName": accountName,
          "priorityName": this.priorityName
        }).then(resp => {
          if (resp.data.code == 200) {
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
             this.priorityName=null
             this.dialogVisible = false
             this.getAllPriority(1, 3)
          } else {
            this.$message.error(resp.data.message)
            this.priorityName=null
          }

        })

      },
      closePriority(pid) {
        this.$http.get("defectPriority/closePriority", {
          params: {
            "priorityId": pid
          }
        }).then(resp => {
          if (resp.data.code == 200) {
            this.$message({
              message: resp.data.message,
              type: 'success'
            })
          } else {
            this.$message.error(resp.data.message)
          }
          this.getAllPriority(1, 3)
        })
      },
      changePriority(pid){
        this.priorityId=pid
        this.$http.get("defectPriority/checkedPriorityState",{
          params:{
            "priorityId":this.priorityId
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.dialogVisible2=true
          }else{
            this.$message.error(resp.data.message)
          }
        })
      },
      delPriority(pid){
        this.$http.get("defectPriority/delPriority",{
          params:{
            "priorityId":pid
          }
        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message:resp.data.message,
              type:'success'
            })
          }else{
            this.$message.error(resp.data.message)
          }
          this.getAllPriority(1,3)
        })
      },
      selByName(){
        this.$http.post("defectPriority/selByName",{"priorityName":this.getByName,
                                                    "current":1,
                                                    "size":3

        }).then(resp=>{
          this.getPrioritByPage=resp.data.data.records
          this.pages=resp.data.data
        })
      },
      surechange(){
        this.$http.post("defectPriority/changePriority",{"priorityId":this.priorityId,
                                                          "priorityName":this.changepriorityName,
                                                          "accountName":JSON.parse(localStorage.getItem("loginUser")).accountName
        }).then(resp=>{
          if(resp.data.code==200){
            this.$message({
              message:resp.data.message,
              type:'success'
            })
this.changepriorityName=null
          this.dialogVisible2=false
          this.getAllPriority(1,3)
          }else{
            this.$message.error(resp.data.message)
            this.changepriorityName=null
          }

        })
     }


    },
    created() {
      this.getAllPriority(1, 3)
    }

  }
</script>

<style>
</style>
